<?php
require_once 'ApibaseController.php';

/**
 * 物件リクエスト問い合わせAPI<br />
 *
 * 物件リクエスト問い合わせAPI
 *
 * @package apamanshop
 * @author ushijima
 * @copyright コピーライト(要確認)
 */
class Inquiry_ApirequestController extends Inquiry_ApibaseController
{
	//====================定数====================
	/** キャンペーン区切り文字 */
	const DELIM_CAMPAIGN = ";";
	/** お宝区切り文字 */
	const DELIM_OTAKARA = ",";

	//店舗情報
	private $shoplist = array();

	/** モバイル区分 */
	private $m_isMobile;
	/** キャリア */
	private $m_carrier;

	/** あげちゃいますキャンペーン(全て)(Key:キャンペーンコード  Value:キャンペーン情報) */
	private $m_arrCampaignAgechauAll;
	/** あげちゃいますキャンペーン(Key:キャンペーンコード  Value:キャンペーン情報) */
	private $m_arrCampaignAgechau;
	/** あげちゃいますキャンペーンお宝(Key:キャンペーンコード  Value:お宝情報リスト) */
	private $m_arrCampaignAgechauTakara;
	/** 部屋付きキャンペーン（反響カウント用） */
	private $m_arrCampaignHeya;
	/** 部屋付きキャンペーン（メールタイトル用）(Key:キャンペーンコード  Value:キャンペーン情報) */
	private $m_arrCampaignHeyaList;

	/** W75LETTERS_CAMPAIGN 登録/更新件数 */
	private $m_insupdW75LettersCampaignCnt;
	/** W76APPLY_CAMPAIGN 登録件数 */
	private $m_insW76ApplyCampaignCnt;
	/** W25CAMPAIGN_DOWNLOAD_MNG 登録件数 */
	private $m_insW25CampaignDownloadMngCnt;

	/** 問い合わせID */
	private $m_strToiawaseId;

	/**
	 * 物件リクエスト問合せAPIアクション
	 *
	 * @access public
	 * @return void
	 */
	public function indexAction()
	{
		//=====結果件数初期化=====
		$this->m_insupdW75LettersCampaignCnt = 0;
		$this->m_insW76ApplyCampaignCnt = 0;
		$this->m_insW25CampaignDownloadMngCnt = 0;

		// パラメータ編集用
		$add_params = array();

		// モバイル区分・ジャンルコード
		$strGenruFlg = "";
		$this->m_carrier = "";
		if (isset($this->_params['isMobile']) && !empty($this->_params['isMobile'])) {
			$this->m_isMobile = $this->_params['isMobile'];
			$strGenruFlg      = $this->_params['vintGenruFlg'];
			if (empty($strGenruFlg)) {
				$strGenruFlg = "1";
			}
			// iPhone、スマホ、Android用設定
			else if ($strGenruFlg == '91' || $strGenruFlg == '92') {
				$this->m_isMobile = '2';
				$this->m_carrier = "iPhone";
			}
			else if ($strGenruFlg == '93' || $strGenruFlg == '94') {
				$this->m_isMobile = '4';
				$this->m_carrier = "Android";
			}
			else if ($strGenruFlg == '95' || $strGenruFlg == '96') {
				$this->m_isMobile = '3';
				$this->m_carrier = "スマートフォン";
			}
		} else {
			$this->m_isMobile = "0";
			$strGenruFlg      = "0";
		}

		//都道府県コード
		$strPrefCd = $this->_params['PrefCd'];
		//市区町村コード
		$strCityCd = $this->_params['CityCd'];
		//町コード
		$strTownCd = $this->_params['TownCd'];
		//沿線コード
		$strRailCd = $this->_params['RailCd'];
		//駅コード
		$strStCd = $this->_params['StCd'];

		//検索区分
		$strSrhKbn = $this->_params['SrhKbn'];
		//検索タイプ
		$strSrhType = $this->_params['SrhType'];

		//設定しなおし
		$strCondDsp = str_replace(" ",", ",$this->_params['condDsp']);

		//賃料
		$inttinryo1 = $this->_params['tinryo1'];
		$inttinryo2 = $this->_params['tinryo2'];
		$strtinryo_jouken2 = $this->_params['tinryo_jouken2'];
		$strtyusyajyo_komi = $this->_params['tyusyajyo_komi'];
		$strmeyasu_tinryo = $this->_params['meyasu_tinryo'];
		$strfreerent = $this->_params['freerent'];
		$strshikireizero = $this->_params['shikireizero'];
		$strshikikin_nashi = $this->_params['shikikin_nashi'];
		$strreikin_nashi = $this->_params['reikin_nashi'];
		$strshataku_koujyo = $this->_params['shataku_koujyo'];
		$strheyawari = $this->_params['heyawari'];
		//初期費用
		$strsyokihiyo = $this->_params['syokihiyo'];
		//建物種別
		$strsyubetu1 = $this->_params['syubetu1'];
		$strsyubetu2 = $this->_params['syubetu2'];
		$strsyubetu3 = $this->_params['syubetu3'];
		$strsyubetu4 = $this->_params['syubetu4'];
		$strsyubetu5 = $this->_params['syubetu5'];
		//駅徒歩
		$intekitoho = $this->_params['ekitoho'];
		$strbas_riyou = $this->_params['bas_riyou'];
		//占有面積
		$strsenyu1 = $this->_params['senyu1'];
		$strsenyu2 = $this->_params['senyu2'];
		//間取り
		$strmadori10 = $this->_params['madori10'];
		$strmadori11 = $this->_params['madori11'];
		$strmadori12 = $this->_params['madori12'];
		$strmadori14 = $this->_params['madori14'];
		$strmadori21 = $this->_params['madori21'];
		$strmadori22 = $this->_params['madori22'];
		$strmadori24 = $this->_params['madori24'];
		$strmadori31 = $this->_params['madori31'];
		$strmadori32 = $this->_params['madori32'];
		$strmadori34 = $this->_params['madori34'];
		$strmadori41 = $this->_params['madori41'];
		$strmadori42 = $this->_params['madori42'];
		$strmadori44 = $this->_params['madori44'];
		$strmadori51 = $this->_params['madori51'];

		//築年数
		$intbuilt = $this->_params['built'];
		//情報の新しさ
		$strjyohou = $this->_params['jyohou'];

		//個人情報ﾊﾟﾗﾒｰﾀ
		$strNameSei = $this->_params['NameSei'];
		$strNameMei = $this->_params['NameMei'];
		$this->_params['Name'] = trim(trim($strNameSei) . "　" . trim($strNameMei), "　");
		$strMail = $this->_params['Mail'];
		$strTel = $this->_params['Tel'];
		$strNeedTimeKbn = $this->_params['NeedTimeKbn'];
		$strFax = $this->_params['Fax'];
		$strInqryContents = $this->_params['Comment'];
		$strCntctWayMail = $this->_params['CntctWayMail'];
		$strCntctWayTel  = $this->_params['CntctWayTel'];
		$strCntctWayFax  = $this->_params['CntctWayFax'];

		//店舗コード配列化
		$add_params['arrSelShop'] = $this->_params['SelShop'];

		//送信時刻
		$strTimeStr = $this->_params['TimeStr'];

		if($strPrefCd == "" && $strCityCd == "" && $strStCd == "") {
			//予期せぬエラー
			$result = 0;
		} else {

			//-----駅徒歩(DspEkitoho)
			if ($intekitoho == "0") {
				$add_params['DspEkitoho'] = "指定なし";
			} else {
				$add_params['DspEkitoho'] = $intekitoho . "分以内";

				//INSERT START リクエストメールの条件記入漏れ対応 2011/10/17 ss-sakakibara
				if ($strbas_riyou == "on") {
					$add_params['DspEkitoho'] .= "（バス利用可）";
				} else {
					$add_params['DspEkitoho'] .= "（バス利用不可）";
				}
				//INSERT END リクエストメールの条件記入漏れ対応 2011/10/17 ss-sakakibara
			}

			//INSERT START リクエストメールの条件記入漏れ対応 2011/10/17 ss-sakakibara

			//-----情報の新しさ(DspJyohou)
			if($strjyohou == '1'){
				$add_params['DspJyohou'] = "本日更新";
			}
			else if($strjyohou == '3'){
				$add_params['DspJyohou'] = "3日以内更新";
			}
			else if($strjyohou == '7'){
				$add_params['DspJyohou'] = "1週間以内更新";
			}
			else{
				$add_params['DspJyohou'] = "指定なし";
			}
			//INSERT END リクエストメールの条件記入漏れ対応 2011/10/17 ss-sakakibara

			//-----賃料（DspTinryo1,DspTinryo2）
			if ($inttinryo1 == "0") {
				$add_params['DspTinryo1'] = "下限なし";
			} else {
				$add_params['DspTinryo1'] = $inttinryo1/10000 . "万";
			}

			if ($inttinryo2 == "9999999") {
				$add_params['DspTinryo2'] = "上限なし";
			} else {
				$add_params['DspTinryo2'] = $inttinryo2/10000 . "万";
			}

			//INSERT START リクエストメールの条件記入漏れ対応 2011/10/17 ss-sakakibara
			if($inttinryo1 != "0" || $inttinryo2 != "9999999"){
				if ($strmeyasu_tinryo == "normal") {
					$add_params['DspTinryo2'] .= "（賃料）";
				} else {
					$add_params['DspTinryo2'] .= "（めやす賃料）";
				}
			}
			//INSERT END リクエストメールの条件記入漏れ対応 2011/10/17 ss-sakakibara

			//-----間取り(DspMadori)
			if (($strmadori10 != "on" && $strmadori11 != "on" && $strmadori12 != "on" && $strmadori14 != "on" && $strmadori21 != "on" && $strmadori22 != "on" && $strmadori24 != "on" && $strmadori31 != "on" && $strmadori32 != "on" && $strmadori34 != "on" && $strmadori41 != "on" && $strmadori42 != "on" && $strmadori44 != "on" && $strmadori51 != "on") ||
			   ($strmadori10 == "on" && $strmadori11 == "on" && $strmadori12 == "on" && $strmadori14 == "on" && $strmadori21 == "on" && $strmadori22 == "on" && $strmadori24 == "on" && $strmadori31 == "on" && $strmadori32 == "on" && $strmadori34 == "on" && $strmadori41 == "on" && $strmadori42 == "on" && $strmadori44 == "on" && $strmadori51 == "on") )
			{
				$add_params['DspMadori'] = "[全て]";

			} else {

				if ($strmadori10 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1R]";
				}
				if ($strmadori11 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1K]";
				}
				if ($strmadori12 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1DK(+S)]";
				}
				if ($strmadori14 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1LDK(+S)]";
				}
				if ($strmadori21 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[2K]";
				}
				if ($strmadori22 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[2DK(+S)]";
				}
				if ($strmadori24 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[2LDK(+S)]";
				}
				if ($strmadori31 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[3K]";
				}
				if ($strmadori32 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[3DK(+S)]";
				}
				if ($strmadori34 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[3LDK(+S)]";
				}
				if ($strmadori41 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[4K]";
				}
				if ($strmadori42 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[4DK(+S)]";
				}
				if ($strmadori44 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[4LDK(+S)]";
				}
				if ($strmadori51 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[5K～]";
				}
			}

			//-----築年数
			if ($intbuilt == "0") {
				$add_params['DspBuilt'] = "指定なし";
			}else if ($intbuilt == "1") {
				$add_params['DspBuilt'] = "新築";
			} else {
				$add_params['DspBuilt'] = $intbuilt . "年以内";
			}

			//-----専有面積 (0以外だったら値を入れる）
			if ($strsenyu1 != "1") {
				$add_params['DspSenyu']  = $strsenyu1 . "ｍ2以上" . "～";
			}

			if ($strsenyu2 != "99999") {
				$add_params['DspSenyu']  = $add_params['DspSenyu'] . $strsenyu2 . "ｍ2以内";
			}

			if (($strsenyu1 == "1") && ($strsenyu2 == "99999")) {
				$add_params['DspSenyu']  = "限度なし";
			}

			//-----建物種別
			if (($strsyubetu1 == "on" && $strsyubetu2 == "on" && $strsyubetu3 == "on" && $strsyubetu4 == "on" && $strsyubetu5 == "on") ||
				($strsyubetu1 == "" && $strsyubetu2 == "" && $strsyubetu3 == "" && $strsyubetu4 == "" && $strsyubetu5 == ""))
			{
				$add_params['DspSyubetu'] = "[全て]";

			} else {

				if ($strsyubetu1 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[賃貸アパート]";
				}
				if ($strsyubetu2 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[賃貸マンション]";
				}
				if ($strsyubetu3 == "on") {
//					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[賃貸一戸建て・借家・テラスハウス]";
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[戸建て・テラスハウス]";
				}
				if ($strsyubetu4 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[貸店舗・賃貸事務所]";
				}
				if ($strsyubetu5 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[駐車場]";
				}
			}

			//（管理費・共益費込み）
			if ($strtinryo_jouken2 == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[管理費・共益費込み]";
			}
			// INSERT_STRART リクエストメールの表示エラー　ss-sakakibara 2011-10-14
			//（駐車場代込み）
			if ($strtyusyajyo_komi == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[駐車場代込み]";
			}
			// INSERT_END リクエストメールの表示エラー　ss-sakakibara 2011-10-14

			//（フリーレント）
			if ($strfreerent == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[ﾌﾘｰﾚﾝﾄ]";
			}
			//（敷金礼金０）
			// ----- UPDATE Start 2011/06/20 ダブルゼロ分割対応 SS Ishii-n -----
			//if ($strshikikin_nashi == "on" && $strreikin_nashi == "on"){
			if (($strshikikin_nashi == "on" && $strreikin_nashi == "on") || ($strsyokihiyo != "" && $strsyokihiyo == "w0")){
			// ----- UPDATE End   2011/06/20 ダブルゼロ分割対応 SS Ishii-n -----
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[敷金・礼金0]";
			}else if ($strshikikin_nashi == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[敷金0]";
			}else if ($strreikin_nashi == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[礼金0]";
			}
			//（部屋割）
			if ($strheyawari == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[部屋割]";
			}
			// ----- INSERT Start 2011/06/20 ダブルゼロ分割対応 SS Ishii-n -----
			//（初期費用）
			if ($strsyokihiyo != "" && $strsyokihiyo > "0" && $strsyokihiyo <> "w0") {
				if ($strsyokihiyo == "99") {
					$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[初期費用0円]";
				} else {
					$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[初期費用".$strsyokihiyo."万円]";
				}
			}
			// ----- INSERT End   2011/06/20 ダブルゼロ分割対応 SS Ishii-n -----

			//--------------------------------------------------------
			//= 選択ﾒﾆｭｰ別変数初期化取得処理
			//--------------------------------------------------------

			switch($strSrhType) {

				//@ 住所を選択する(eki)
				Case "1":

					$add_params['DspKibouToshi'] = $strCondDsp;
					$add_params['DspKibouEnsen'] = "";
					$add_params['DspKibouEki'] = "";
					break;

				//@ 沿線を選択する(pref, skchsn)
				Case "2";

					$add_params['DspKibouToshi'] = "";
					$add_params['DspKibouEnsen'] = $strCondDsp;
					$add_params['DspKibouEki'] = "";
					break;

			}

		//--------------------------------------------------------
		//= 表示情報設定処理
		//--------------------------------------------------------

			//@ 希望連絡手段(表示)
			$strCntctWayStr = "";
			//希望連絡(ﾒｰﾙ)が設定されている場合
			if ($strCntctWayMail == "1") {
				$strCntctWayStr = $strCntctWayStr . "メール，";
			}
			//希望連絡(TEL)が設定されている場合
			if ($strCntctWayTel == "1") {
				$strCntctWayStr = $strCntctWayStr . "ＴＥＬ，";
			}
			//希望連絡(FAX)が設定されている場合
			if ($strCntctWayFax == "1") {
				$strCntctWayStr = $strCntctWayStr . "ＦＡＸ，";
			}
			if ($strCntctWayStr != "") {
				$strCntctWayStr = rtrim($strCntctWayStr,"，");
			}
			$add_params['CntctWayStr'] = $strCntctWayStr;

			//@ 希望連絡手段CD
			$strCntctWayCd = "";
			//希望連絡(TEL)が設定されている場合
			if ($strCntctWayTel == "1") {
				$strCntctWayCd = $strCntctWayCd . "1";
			} else {
				$strCntctWayCd = $strCntctWayCd . "0";
			}
			//希望連絡(ﾒｰﾙ)が設定されている場合
			if ($strCntctWayMail == "1") {
				$strCntctWayCd = $strCntctWayCd . "1";
			} else {
				$strCntctWayCd = $strCntctWayCd . "0";
			}
			//希望連絡(FAX)が設定されている場合
			if ($strCntctWayFax == "1") {
				$strCntctWayCd = $strCntctWayCd . "1";
			} else {
				$strCntctWayCd = $strCntctWayCd . "0";
			}
			$this->_params['CntctWayCd'] = $strCntctWayCd;

			//希望時間
			$arrNeedTimeKbn = Array("希望なし","10時以前","10時～12時","12時～14時","14時～16時","16時～18時","18時以降");

			if ($strNeedTimeKbn != "") {
				$add_params['DspstrNeedTimeKbn'] = $arrNeedTimeKbn[$strNeedTimeKbn];
			}

			//--- メール判定 ---
			$this->setSendMailFlag($this->_params['Mail']);
			// ﾛｸﾞ情報格納処理 *****************************************
			$resApi = array();
			try {
				// モデルの呼び出し
				$this->_model = new Inquiry_Model_Apiinquiry();
				$this->_model_bukken = new Inquiry_Model_Apibukken();

				//トランザクション開始
				$db = $this->_model->getDbConnection();
				//トランザクション開始
				$this->_model->startTransaction($db);

				//店舗情報取得
				if ($this->_params['SelShop'] != "") {
					$this->shoplist = $this->_model->getInqShop2Qry(array_merge($this->_params,$add_params));
					$add_params['tenpoMailShopCount'] = count($this->shoplist);

					foreach($this->shoplist as $key => $value){
						if($firstflg){
							$add_params['TenpoAll2'] = $value['M05_TENPO_NAME'];
							$firstflg = false;
						}else{
							$add_params['TenpoAll2'] = $add_params['TenpoAll2'] . "\r\n" . $value['M05_TENPO_NAME'];
						}
					}
				}

				//こだわり条件文字列
				$add_params['KodawariData'] = $this->setKodawariData($this->_model->GetKodawari());
				//array_push($add_params,$this->setKodawariData($this->_model->GetKodawari()));

				//キャンペーン条件文字列
				$add_params['CampaignData'] = $this->setCampaignData($this->_params['campaign']);

				//問合わせID生成
				$this->m_strToiawaseId = strval($this->GetTimeString()) . strval($this->GetToiawaseSEQ($db));

				$add_params['InqNo'] = $this->m_strToiawaseId;
				$add_params['ComGenruFlg'] = $strGenruFlg;
				$add_params['Seqcount'] = 0;

				//問合せﾕｰｻﾞ情報格納ｸｴﾘ取得処理
				array_push($resApi,$this->_model->insInqUserLog3($db,$this->_params,$add_params));

				// 問い合わせログ格納処理（モバイルのみ）：strShudanが存在する場合のみ含めるように暫定対応
				if ($this->m_isMobile != "0"
					&& isset($this->_params['strShudan']) && !Apm_Otheritems::IsNullOrEmpty($this->_params['strShudan'])) {

					$loader = new Zend_Application_Module_Autoloader(array(
						'namespace' => 'Mobileapi',
						'basePath' => APPLICATION_PATH . '/modules/mobileapi',
					));
					$model_mobileapi = new Mobileapi_Model_Bukkenrequest();
					$api_params = array();
					$api_params['strToiawaseID']        = $this->m_strToiawaseId;
					$api_params['strKensakuFlag']       = "1";
					$api_params['vintGenruFlg']         = $strGenruFlg;
					$api_params['weekday']              = date('w')+1;
					$api_params['strName']              = $this->_params['Name'];
					$api_params['strJob']               = $this->_params['strJob'];
					$api_params['str_In_Todoufuken_Cd'] = $this->_params['str_In_Todoufuken_Cd'];
					$api_params['strMail']              = $strMail;
					$api_params['strTel']               = $strTel;
					$api_params['strShudan']            = $this->_params['strShudan'];
					array_push($resApi,$model_mobileapi->insToiawaseLog($db,$api_params));
				}

				$add_params['targetPrefCd'] = '';
				$add_params['targetCityCd'] = '';
				$add_params['targetTownCd'] = '';
				$add_params['targetRailCd'] = '';
				$add_params['targetStCd']   = '';
				if($strSrhType == "1") {
					if($strTownCd != "") {
						foreach($strTownCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetPrefCd'] = mb_substr($val,0,2);
							$add_params['targetCityCd'] = mb_substr($val,2,3);
							$add_params['targetTownCd'] = mb_substr($val,5,3);
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}else if($strCityCd != "") {
						foreach($strCityCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetPrefCd'] = mb_substr($val,0,2);
							$add_params['targetCityCd'] = mb_substr($val,2,3);
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}else if ($strPrefCd != ""){
						foreach($strPrefCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetPrefCd'] = mb_substr($val,0,2);
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}
				}else if($strSrhType == "2") {
					if($strStCd != "") {
						foreach($strStCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetRailCd'] = mb_substr($val,0,4);
							$add_params['targetStCd'] = $val;
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}else if($strRailCd != "") {
						foreach($strRailCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetRailCd'] = $val;
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
						}
					}
				}
				//ログ登録
				$add_params['tenpoNmAllMailSend'] = "";
				$add_params['tenpoMailAllMailSend'] = array();
				$add_params['ViewKbn'] = "4";
				//$add_params['ComGenruFlg'] = "0";
				$add_params['OrgHeyaCd'] = "";
				if(empty($this->shoplist)) {
					//ページビュー情報
					$this->_params['ShopCd'] = " ";
					if($this->isLogIns() == true) {
						array_push($resApi,$this->_model->pageViewLog($db,$this->_params,$add_params));
						//リクエスト検索情報ログ
						//データセット
						$add_params['ReqData'] = $this->setRequestData();
//						array_push($add_params,$this->setRequestData());
						array_push($resApi,$this->_model->requestKensakuLog($db,$this->_params,$add_params));
						//リクエスト手動メール情報登録
						array_push($resApi,$this->_model->InsRequestShudouLog($db,$this->_params,$add_params));
					}
				}else{
					foreach($this->shoplist as $key => $value){
						//ページビュー情報
						$this->_params['ShopCd'] = $value['M05_TENPO_CD'];
						if($value['M05_TENPO_MAIL'] != ""){
							$add_params['tenpoNmAllMailSend'] .= $value['M05_TENPO_NAME'] . " ";
							array_push($add_params['tenpoMailAllMailSend'],array($value['M05_TENPO_MAIL'] => ""));
						}
						if($this->isLogIns() == true) {
							array_push($resApi,$this->_model->pageViewLog($db,$this->_params,$add_params));
						}
					}
				}

				//--- あげちゃいますキャンペーン初期化 ---
				$this->MakeCampaignAgechau($this->_params["CampaignAgechau"]);

				//=====キャンペーン反響テーブルカウント(あげちゃいます)=====
				foreach ($this->m_arrCampaignAgechau as $key => $value)
				{
					$this->UpdLettersCampaign($db, $value["M94_CAMPAIGN_KBN"], $value["M94_CAMPAIGN_CD"], 2);
				}

				//あげちゃいますキャンペーンはDBからデータ取得
				//お宝の表示は行わない
				$add_params['strDownloadUrl'] = "";
				$add_params['campaign'] = "";
				foreach ($this->m_arrCampaignAgechauAll as $campaignAll)
				{
					if(array_key_exists($campaignAll["M94_CAMPAIGN_CD"], $this->m_arrCampaignAgechau))
					{
						if($campaignAll["M94_CAMPAIGN_CD"] <> "17"){
							$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　応募する\n";
						}
						else{
							$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　希望する\n";
						}
						$add_params['campaign_str'] .= "　　　◆◆◆" . $campaignAll["M94_CAMPAIGN_NAME"] . "◆◆◆に、応募\n";
					}
					//else
					//{
					//	if($campaignAll["M94_CAMPAIGN_CD"] <> "17"){
					//		$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　応募しない\n";
					//	}
					//	else{
					//		$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　希望しない\n";
					//	}
					//}

					// アパマン48キャンペーン期間か
					if($campaignAll["M94_CAMPAIGN_CD"] == Apm_Config_Inquiry::AKB_CAMPAIGN_CD)
					{
						//=====キャンペーンダウンロード管理登録
						$this->m_insW25CampaignDownloadMngCnt += $this->_model_bukken->InsCampaignDownload($db, $this->m_strToiawaseId, $campaignAll["ACCESS_KEY"]);

						$add_params['isMobile'] = $this->m_isMobile;
						$add_params['strApaman48DownloadUrl'] = $this->_config['apm']['baseurl']. "AKB48/cp/download?id=". $this->m_strToiawaseId. "&key=".$campaignAll["ACCESS_KEY"];
					}
					//=====キャンペーンダウンロード管理
					if($campaignAll["M94_CAMPAIGN_CD"] == Apm_Config_Inquiry::EXILE_CAMPAIGN_CD)
					{
						// DB登録
						$this->m_insW25CampaignDownloadMngCnt += $this->_model_bukken->InsExileCampaignDownload($db, $this->m_strToiawaseId, $this->m_isMobile, $campaignAll["ACCESS_KEY"]);
						// URI生成
						if ($this->m_isMobile == "0") {
							// PC
							$strExileDownloadUrl = $this->_config['apm']['baseurl']. "exile/cp/download?id=". $this->m_strToiawaseId. "&key=".$campaignAll["ACCESS_KEY"];
						}
						else if ($this->m_isMobile == "1") {
							// mobile
							$strExileDownloadUrl = $this->_config['apm']['baseurl']. "mobile/exile/download?id=". $this->m_strToiawaseId. "&key=".$campaignAll["ACCESS_KEY"];
						}
						else {
							// SP
							$strExileDownloadUrl = $this->_config['apm']['baseurl']. "exile/cp/download/sp?id=". $this->m_strToiawaseId. "&kbn=".$this->m_isMobile. "&key=".$campaignAll["ACCESS_KEY"];
						}
						// メールMSG生成
						$strDownloadMsg = "";
						if ($this->m_isMobile == "0") {
							// PC
							$strDownloadMsg .= "■スクリーンセーバーダウンロード\n";
							$strDownloadMsg .= "現在、APAMANxEXILEキャンペーン中につき、お問合わせいただいた方全員に\n";
							$strDownloadMsg .= "もれなくAPAMANxEXILEオリジナルスクリーンセーバーを差し上げています。\n";
							$strDownloadMsg .= "下記、URLからダウンロードしてお楽しみください。\n";
							$strDownloadMsg .= "※ダウンロードは3回までとなっておりますのでご注意ください。\n";
						}
						else {
							$strDownloadMsg .= "■壁紙ダウンロード\n";
							$strDownloadMsg .= "現在、APAMANxEXILEキャンペーン中につき、お問合わせいただいた方全員に\n";
							$strDownloadMsg .= "もれなくAPAMANxEXILEオリジナル壁紙を差し上げています。\n";
							$strDownloadMsg .= "下記、URLからダウンロードしてお楽しみください。\n";
						}
						$strDownloadMsg .= " \n";
						$strDownloadMsg .= $strExileDownloadUrl."\n";

						$add_params['strDownloadUrl'] .= $strDownloadMsg;
					}
				}

				// INSERT START　リクエスト・店舗問い合わせログの記録 2011/09/26 ss-sakakibara
				//=====ログ情報保存=====
				if ($this->isLogIns())
				{
					if(empty($this->_params['SelShop'])){
						$this->_model->InsInqTenpoLog($this->m_strToiawaseId, "", $db);
					}
					else{
					foreach ($this->_params['SelShop'] as $shopId){
							$this->_model->InsInqTenpoLog($this->m_strToiawaseId, $shopId, $db);
						}
					}
				}
				// INSERT END　リクエスト・店舗問い合わせログの記録 2011/09/26 ss-sakakibara

				// ﾒｰﾙ送信処理 ********************************************
				$result =  $this->SendMailMain($strMail,$add_params);
				if($result == "0"){
					 $this->raiseError('メール送信エラー');
				}

				__log_debug(__FILE__, __LINE__, __METHOD__, "コミットします");
				$this->_model->commitTransaction($db);
				$db->closeConnection();

				$result = 1;

			} catch (Exception $e) {
				__log_debug(__FILE__, __LINE__, __METHOD__, "ロールバックします");
				$this->_model->rollbackTransaction($db);
				$db->closeConnection();
				$result = 0;
			}
		}
		// 返却データ作成
		$resResult = array('api_result' => array('result' => $result,'res_detail' => $resApi));
		$resResult['CV_ToiawaseId'] = $this->m_strToiawaseId;
		// 返却処理
		$this->_api_data = $resResult;
		$this->display();

	}

	public function postAction() {

		/* add 20141230 　かんたんリクエスト登録時のみ　*/
		if( $this->_params['Method'] == 'regist' ){
			session_start();

			$pa_names = array('area', 'PrefCd', 'CityCd', 'RailCd', 'StCd1', 'StCd2', 'StCd3', 'tinryo', 'madori', 'menseki', 'ekitoho');
			$sess_vals = array();

			foreach ($pa_names as $name){
				$sess_vals[$name] = $this->_params[$name];
			}

			$_SESSION['_REQUESTSEARCH_PARAMS'] = $sess_vals;

			$this->requestSearch_CompleteProcess();
			header("Location:../../requestsearch/complete/");
			exit();
		}
		/* add 20141230 end */
	}
	//メール送信制御
	private function SendMailMain($mail,$addinfo) {
		// ｽﾃｰﾀｽ初期化
		$userResult = 1;
		$shopResult = 1;
		$officeResult = 1;


		// 店舗へのメール送信
		$shopResult = $this->SendMailShop($addinfo);

		// 本部へのメール送信
		$officeResult = $this->SendMailOffice($addinfo);

		// ユーザへメール送信
		if ($mail != "") {
			$userResult = $this->SendMailUser($mail,$addinfo);
		}

		$result = 1;
		//メール送信チェック
		if ( $userResult == 0 || $shopResult == 0 || $officeResult == 0) {
			$result = 0;
		}
		return $result;
	}

	// 問い合わせユーザへのメール送信
	private function SendMailUser($mail,$addinfo) {
		// ｽﾃｰﾀｽ初期化
		$result = 1;

		// from(送信元)、to（あて先)
		$strMailTo = array($mail => "");								//送信先ﾒｰﾙｱﾄﾞﾚｽ
		$strMailFrom = array(Apm_Config_Mail::MAIL_NETWORK => "");		//送信元ﾒｰﾙｱﾄﾞﾚｽ

		// メール本文に必要なパラメータ
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] =  "［アパマンショップ］物件リクエスト登録のご確認";
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;

		// メールテンプレート
		$strMailTmp = "";
		if ($this->m_isMobile == "1") {
			$strMailTmp = "MailRequestUserMobile.tpl";	// モバイル
		} else if ($this->m_isMobile == "3") {
			$strMailTmp = "MailRequestUserSp.tpl";		// スマホ
		} else {
			$strMailTmp = "MailRequestUser.tpl";		// PC
		}

		// ﾒｰﾙ送信処理
		$result = $this->sendToiawaseMailJudge($strMailTmp, array_merge($this->_params,$addinfo), $mail_params, 3);
		//if($this->isSendUser() == true) {
		//	$result = $this->sendToiawaseMail($strMailTmp, array_merge($this->_params,$addinfo), $mail_params);
		//}

		return $result;
	}

	// 本部のメール送信
	private function SendMailOffice($addinfo) {

		$strSubject = "リクエストメール配信履歴";
		// キャリア付加
		if (!empty($this->m_carrier)) {
			$strSubject .= "＜{$this->m_carrier}版＞";
		}
		$strMailTo =   array(Apm_Config_Mail::MAIL_NETWORK => "");	//送信先ﾒｰﾙｱﾄﾞﾚｽ
		$strMailFrom = array(Apm_Config_Mail::MAIL_NETWORK => "");	//送信元ﾒｰﾙｱﾄﾞﾚｽ
		$strMailCc = array(Apm_Config_Mail::MAIL_NETWORK_CALL => "");

		//@ 送信先ﾒｰﾙｱﾄﾞﾚｽ
		// 本文の設定
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] = $strSubject;
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_CC_KEY] = $strMailCc;

		// メールテンプレート
		$strMailTmp = "";
		if ($this->m_isMobile == "3") {
			$strMailTmp = "MailRequestHonbuSp.tpl";	// スマホ
		} else {
			$strMailTmp = "MailRequestHonbu.tpl";		// PC
		}

		$result = $this->sendToiawaseMailJudge($strMailTmp ,array_merge($this->_params,$addinfo), $mail_params, 1);
		//if($this->isSendHonbu() == true) {
		//	// ﾒｰﾙ送信処理
		//	$result = $this->sendToiawaseMail("MailRequestHonbu.tpl",array_merge($this->_params,$addinfo), $mail_params);
		//}else if($this->getReplaceHonbuMail() != "") {
		//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = array($this->getReplaceHonbuMail() => "");
		//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_CC_KEY] = array($this->getReplaceHonbuMail() => "");
		//	// ﾒｰﾙ送信処理
		//	$result = $this->sendToiawaseMail("MailRequestHonbu.tpl",array_merge($this->_params,$addinfo), $mail_params);
		//}

		return $result;
	}


	// 店舗へのメール送信
	private function SendMailShop($addinfo) {
		// ｽﾃｰﾀｽ初期化
		$result = true;

		if(empty($this->shoplist)){

			foreach($this->_params['PrefCd'] as $value){
				if ($intEastSend == 0) {
					if ($tantousha == "") {
						$strTo = array(Apm_Config_Mail::MAIL_KANTOU => "");
					}else{
						$strTo = array($tantousha => "",Apm_Config_Mail::MAIL_KANTOU => "");
					}
			        $intEastSend = 1;
				}
			}
			if (empty($strTo)) {
				$strTo = array(Apm_Config_Mail::MAIL_KANTOU => "");
			}

			$strSubject = "リクエストメール該当店舗なし";
			// キャリア付加
			if (!empty($this->m_carrier)) {
				$strSubject .= "＜{$this->m_carrier}版＞";
			}
			$strMailTo =   $strTo;											//送信先ﾒｰﾙｱﾄﾞﾚｽ
			$strMailFrom = array(Apm_Config_Mail::MAIL_NETWORK => "");		//送信元ﾒｰﾙｱﾄﾞﾚｽ
			$strMailReply = array($this->_params['Mail'] => "");

			//@ 送信先ﾒｰﾙｱﾄﾞﾚｽ
			// 本文の設定
			$mail_params = array();
			$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] = $strSubject;
			$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
			$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;
			$mail_params[Apm_Otheritems::SEND_MAIL_EX_REPLY_TO_KEY] = $strMailReply;

			// メールテンプレート
			$strMailTmp = "";
			if ($this->m_isMobile == "3") {
				$strMailTmp = "MailRequestNoTenpoSp.tpl";	// スマホ
			} else {
				$strMailTmp = "MailRequestNoTenpo.tpl";		// PC
			}

			$result = $this->sendToiawaseMailJudge($strMailTmp, array_merge($this->_params,$addinfo), $mail_params, 1);
			//if($this->isSendHonbu() == true) {
			//	// ﾒｰﾙ送信処理
			//	$result = $this->sendToiawaseMail("MailRequestNoTenpo.tpl",array_merge($this->_params,$addinfo), $mail_params);
			//}else if($this->getReplaceHonbuMail() != "") {
			//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = array($this->getReplaceHonbuMail() => "");
			//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_REPLY_TO_KEY] = array($this->getReplaceHonbuMail() => "");
			//	// ﾒｰﾙ送信処理
			//	$result = $this->sendToiawaseMail("MailRequestNoTenpo.tpl",array_merge($this->_params,$addinfo), $mail_params);
			//}

		}else {

			foreach($this->shoplist as $key => $val){

				if($val['M05_TENPO_MAIL'] != "") {
					$strSubject = "◆アパマンショップ・リクエストメール";
					// キャリア付加
					if (!empty($this->m_carrier)) {
						$strSubject .= "＜{$this->m_carrier}版＞";
					}
					$strMailTo = array($val['M05_TENPO_MAIL'] => "");								//送信先ﾒｰﾙｱﾄﾞﾚｽ
					$strMailFrom = array(Apm_Config_Mail::MAIL_NETWORK_INFO => "");		//送信元ﾒｰﾙｱﾄﾞﾚｽ
					$strMailReply = array($this->_params['Mail'] => "");
					$strMailCc = array();
					// 特定アドレスのCC追加
					$cc_list = Apm_Config_Inquiry::$SHOP_MAIL_CC_REQUEST[$val['M05_TENPO_CD']];
					if (!empty($cc_list) && is_array($cc_list)) {
						foreach ($cc_list as $ccMail) {
							$strMailCc[$ccMail] = "";
						}
					}

					//@ 送信先ﾒｰﾙｱﾄﾞﾚｽ
					// 本文の設定
					$mail_params = array();
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] = $strSubject;
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_REPLY_TO_KEY] = $strMailReply;
					if (count($strMailCc) > 0) {
						$mail_params[Apm_Otheritems::SEND_MAIL_EX_CC_KEY] = $strMailCc;
					}
					if ($this->isAosShop($val['M05_TENPO_CD']) == true) {
						$mail_params[Apm_Otheritems::SEND_MAIL_EX_HEADER_KEY] = $this->GetMailAosParam("");
					}

					// メールテンプレート
					$strMailTmp = "";
					if ($this->m_isMobile == "3") {
						$strMailTmp = "MailRequestTenpoSp.tpl";	// スマホ
					} else {
						$strMailTmp = "MailRequestTenpo.tpl";		// PC
					}

					$result = $this->sendToiawaseMailJudge($strMailTmp, array_merge($this->_params,$addinfo), $mail_params, 2);
					//if($this->isSendShop() == true) {
					//	// ﾒｰﾙ送信処理
					//	$result = $this->sendToiawaseMail("MailRequestTenpo.tpl",array_merge($this->_params,$addinfo), $mail_params);
					//}else if($this->getReplaceShopMail() != "") {
					//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = array($this->getReplaceShopMail() => "");
					//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_REPLY_TO_KEY] = array($this->getReplaceShopMail() => "");
					//	// ﾒｰﾙ送信処理
					//	$result = $this->sendToiawaseMail("MailRequestTenpo.tpl",array_merge($this->_params,$addinfo), $mail_params);
					//}
				}else{
					$strSubject = "リクエスト配信エラー";
					$strMailTo =  array(Apm_Config_Mail::MAIL_NETWORK => "");		//送信先ﾒｰﾙｱﾄﾞﾚｽ
					$strMailFrom = array(Apm_Config_Mail::MAIL_NETWORK => "");		//送信元ﾒｰﾙｱﾄﾞﾚｽ
					//$strMailReply = array($this->_params['Mail'] => "");	// 不要

					//@ 送信先ﾒｰﾙｱﾄﾞﾚｽ
					// 本文の設定
					$mail_params = array();
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] = $strSubject;
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
					$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;
					//$mail_params[Apm_Otheritems::SEND_MAIL_EX_REPLY_TO_KEY] = $strMailReply;

					// メールテンプレート
					$strMailTmp = "";
					if ($this->m_isMobile == "3") {
						$strMailTmp = "MailRequestTenpoErrMailaddSp.tpl";	// スマホ
					} else {
						$strMailTmp = "MailRequestTenpoErrMailadd.tpl";		// PC
					}

					$result = $this->sendToiawaseMailJudge($strMailTmp, array_merge($this->_params,$addinfo), $mail_params, 1);
					//if($this->isSendHonbu() == true) {
					//	// ﾒｰﾙ送信処理
					//	$result = $this->sendToiawaseMail("MailRequestTenpoErrMailadd.tpl",array_merge($this->_params,$addinfo), $mail_params);
					//}else if($this->getReplaceHonbuMail() != "") {
					//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = array($this->getReplaceHonbuMail() => "");
					//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_REPLY_TO_KEY] = array($this->getReplaceHonbuMail() => "");
					//	// ﾒｰﾙ送信処理
					//	$result = $this->sendToiawaseMail("MailRequestTenpoErrMailadd.tpl",array_merge($this->_params,$addinfo), $mail_params);
					//}

				}
			}

		}

		return $result;
	}

	/**
	 * 各種条件文字列化
	 * @param unknown_type $reslist
	 */
	private function setKodawariData($reslist){
		$max = 0;
		foreach($reslist as $key => $value){
			if($value['W74_KODAWARI_ID'] > $max){
				$max = $value['W74_KODAWARI_ID'];
			}
		}

		$temp['HKodawari'] = "";
		$temp['vKodawari'] = str_repeat('0',$max);
		//こだわり条件Text&DB
		foreach($reslist as $key => $value){
			if($this->_params['kodawari' . $value['W74_KODAWARI_ID'] ] != ""){
				$temp['HKodawari'] .= "[" . $value['W74_KODAWARI_NAME']  . "]";
				$temp['vKodawari'] = $this->repKodawari($temp['vKodawari'],$value['W74_KODAWARI_ID'],$max);
			}
		}

		return $temp;
	}

	/**
	 * こだわり文字列置換処理
	 * @param unknown_type $value 置換文字列値
	 * @param unknown_type $tarIdx 変換位置
	 * @param unknown_type $max 最大桁数
	 */
	private function repKodawari($value,$tarIdx,$max){

		if (($max - $tarIdx) == 0)
		{
			return (mb_substr($value,0,$tarIdx -1) . "1");
		}
		else
		{
			return (mb_substr($value,0,$tarIdx -1) . "1" . mb_substr($value,-1 * ($max - $tarIdx)));
		}

	}

	/**
	 * 各種条件文字列化
	 * @param unknown_type $reslist
	 */
	private function setRequestData(){

		//===HP用配列
		//$arrYachin = Array ("0", "20000", "25000", "30000", "35000", "40000", "45000", "50000", "55000", "60000", "65000", "70000", "75000", "80000", "85000", "90000", "95000", "100000", "110000", "120000", "130000", "140000", "150000", "200000", "250000", "300000", "350000", "500000", "1000000", "9999999");
		//$arrSenyu = Array( "1", "15", "20", "25", "30", "35", "40", "45", "50", "60", "70", "80", "90", "100", "99999");
		//$arrTatemonoTypeOn = Array("1","1","1","1","1");	//1.[賃貸アパート]・2.[賃貸マンション]・3.[賃貸一戸建て・借家]・4.[貸店舗・賃貸事務所]・5.[駐車場]
		//$arrTatemonoTypeOff = Array("0","0","0","0","0");	//1.[賃貸アパート]・2.[賃貸マンション]・3.[賃貸一戸建て・借家]・4.[貸店舗・賃貸事務所]・5.[駐車場]
		//$arrMadoriOn = Array("1","1","1","1","1","1","1","1","1","1","1");
		//$arrMadoriOff = Array("0","0","0","0","0","0","0","0","0","0","0");

		$i = 0;
		//==賃料（下限）
		$temp['iYachinMin'] = 1;
		foreach (Apm_Config_Search::$KENSAKU_CHINRYO_MIN as $key => $val){
			if ($this->_params['tinryo1'] == $key) {
				$temp['iYachinMin'] = $i+1;
				break;
			}
			$i++;
		}

		$i = 0;
		//==賃料（上限）
		$temp['iYachinMax'] = 30;
		foreach (Apm_Config_Search::$KENSAKU_CHINRYO_MAX as $key => $val){
			if ($this->_params['tinryo2'] == $key) {
				$temp['iYachinMax'] = $i+1;
				break;
			}
			$i++;
		}

		//==管理費込みフラグ
		if ($this->_params['tinryo_jouken2'] == "on") {
				$temp['iKanrihiFlg'] = 1;
		}else {
				$temp['iKanrihiFlg'] = 0;
		}

		//==フリーレントフラグ
		if ($this->_params['freerent'] == "on") {
				$temp['iFreeRentFlg'] = 1;
		}else {
				$temp['iFreeRentFlg'] = 0;
		}

		//==敷金礼金０フラグ
		if ($this->_params['shikireizero'] == "on") {
				$temp['iShikireiFlg'] = 1;
		}else {
				$temp['iShikireiFlg'] = 0;
		}

		//==部屋割フラグ
		if ($this->_params['heyawari'] == "on") {
				$temp['iHeyaWariFlg'] = 1;
		}else {
				$temp['iHeyaWariFlg'] = 0;
		}

		//==建物種別
		//1.[賃貸アパート]・2.[賃貸マンション]・3.[賃貸一戸建て・借家]・4.[貸店舗・賃貸事務所]・5.[駐車場]
		//$arrTatemonoType = array($this->_params['syubetu1'],$this->_params['syubetu2'],$this->_params['syubetu3'],$this->_params['syubetu4'],$this->_params['syubetu5']);
		$temp['sTatemonoType'] = "";
		foreach(Apm_Config_Search::$KENSAKU_TATEMONO_SYUBETU as $key => $val) {
			$tatemonoTypeCd = $this->_params[$key];
			if ($tatemonoTypeCd == "on" || $tatemonoTypeCd == "1") {
				$temp['sTatemonoType'] .= "1";
			} else {
				$temp['sTatemonoType'] .= "0";
			}
		}
		//foreach($arrTatemonoType as $key => $val) {
		//	if($val == "on" || $val == "1") {
		//		$temp['sTatemonoType'] .= $arrTatemonoTypeOn[$key];
		//	}else {
		//		$temp['sTatemonoType'] .= $arrTatemonoTypeOff[$key];
		//	}
		//}
		if (mb_strpos($temp['sTatemonoType'],'1') == 0) {
			$temp['sTatemonoType'] = str_replace("0", "1", $temp['sTatemonoType']);
		}

		$i = 0;
		//==駅徒歩
		$temp['iEkitoho'] = 0;
		foreach(Apm_Config_Search::$KENSAKU_TATEMONO_TOHO as $key => $val) {
			if ($this->_params['ekitoho'] == $key) {
				if ($key == '0') {
					$temp['iEkitoho'] = 0;
				} else {
					$temp['iEkitoho'] = $i+1;
				}
				break;
			}
			$i++;
		}

		$i = 0;
		//==専有面積（下限）
		$temp['iSenyuMin'] = 1;
		foreach(Apm_Config_Search::$KENSAKU_SENYU_MENSEKI_MIN as $key => $val) {
			if ($this->_params['senyu1'] == $key) {
				$temp['iSenyuMin'] = $i+1;
				break;
			}
			$i++;
		}

		$i = 0;
		//==専有面積（上限）
		$temp['iSenyuMax'] = 15;
		foreach(Apm_Config_Search::$KENSAKU_SENYU_MENSEKI_MAX as $key => $val) {
			if ($this->_params['senyu2'] == $key) {
				$temp['iSenyuMax'] = $i+1;
				break;
			}
			$i++;
		}

		//==間取り
		/*
		$vaMadori = array(
		$this->_params['madori10'],
		$this->_params['madori11'],
		$this->_params['madori12'],
		$this->_params['madori14'],
		$this->_params['madori21'],
		$this->_params['madori22'],
		$this->_params['madori24'],
		$this->_params['madori31'],
		$this->_params['madori32'],
		$this->_params['madori34'],
		$this->_params['madori41'],
		$this->_params['madori42'],
		$this->_params['madori44'],
		$this->_params['madori51']
		);
		*/
		//==間取り
		$temp['sMadori'] = "";
		foreach(Apm_Config_Search::$KENSAKU_MADORI as $key => $val) {
			$madoriCd = $this->_params[$key];
			if ($madoriCd == "on" || $madoriCd == "1") {
				$temp['sMadori'] .= "1";
			}else {
				$temp['sMadori'] .= "0";
			}
		}
		//if (mb_strpos($temp['sMadori'],"1") == 0) {
		//	$temp['sMadori'] = "00000000000000";
		//}

		$i = 0;
		//==築年数
		$temp['iChikunensu'] = 0;
		foreach(Apm_Config_Search::$KENSAKU_CHIKUNENSU as $key => $val) {
			if ($this->_params['built'] == $key) {
				if ($key == '0') {
					$temp['iChikunensu'] = 0;
				} else {
					$temp['iChikunensu'] = $i+1;
				}
				break;
			}
			$i++;
		}
		//switch ($this->_params['built']) {
		//    case "1":
		//        $temp['iChikunensu'] = 1;
		//        break;
		//    case "3":
		//        $temp['iChikunensu'] = 2;
		//        break;
		//    case "5":
		//        $temp['iChikunensu'] = 3;
		//        break;
	    //    case "10":
		//        $temp['iChikunensu'] = 4;
		//        break;
	    //    default:
		//        $temp['iChikunensu'] = 0;
		//        break;
		//}

		return $temp;
	}

	/**
	 * あげちゃいますキャンペーン情報を作成する
	 * 下記変数の初期化
	 *   $m_arrCampaignAgechauAll
	 *   $m_arrCampaignAgechau
	 *   $m_arrCampaignAgechauTakara
	 */
	private function MakeCampaignAgechau($strCampaignParam)
	{
		//一旦初期化
		$this->m_arrCampaignAgechauAll = array();
		$this->m_arrCampaignAgechau = array();
		$this->m_arrCampaignAgechauTakara = array();
		$this->m_arrCampaignHeya = array();

		$arrSelectCampaign;
		$arrCampaignInfo;

		$arrTakara;

		$campaign;
		$takara;

		// 対象AKBキャンペーン取得
		$this->m_arrCampaignAgechauAll = $this->_model_bukken->GetCampaignEx("2, 4", 1, $this->m_isMobile);

		if (!Apm_Otheritems::IsNullOrEmpty($strCampaignParam))
		{
			//キャンペーン毎に分割
			if (strpos($strCampaignParam, self::DELIM_CAMPAIGN) === false)
			{
				$arrSelectCampaign = array(str_replace(" ", "", $strCampaignParam));
			}
			else
			{
				$arrSelectCampaign = split(self::DELIM_CAMPAIGN, str_replace(" ", "", $strCampaignParam));
			}

			for ($i = 0; $i < count($arrSelectCampaign); $i++)
			{
				$arrTakara = array();
				$campaign = null;
				$takara = null;

				//キャンペーンとお宝を分割
				if (strpos($arrSelectCampaign[$i], self::DELIM_OTAKARA) === false)
				{
					$arrCampaignInfo = array(str_replace(" ", "", $arrSelectCampaign[$i]));
				}
				else
				{
					$arrCampaignInfo = split(self::DELIM_OTAKARA, str_replace(" ", "", $arrSelectCampaign[$i]));
				}

				for ($j = 0; $j < count($arrCampaignInfo); $j++)
				{
					if ($j == 0)
					{
						//先頭はキャンペーンコード
						//キャンペーン情報取得
						$campaign = $this->_model_bukken->GetCampaign("2, 4", $arrCampaignInfo[$j], $this->m_isMobile);
						if (count($campaign) == 0)
						{
							//万一取得できなかった場合はnullにして抜ける
							__log_debug(__FILE__, __LINE__, __METHOD__, $arrCampaignInfo[$j] . "のキャンペーンコードはありません");
							$campaign = null;
							break;
						}
					}
					else
					{
						//２番目以降はお宝コード
						$takara = $this->_model_bukken->GetCampaignTakara($campaign[0]["M94_CAMPAIGN_CD"], $arrCampaignInfo[$j]);
						if (count($takara) > 0)
						{
							//万一取得できなかった場合はnullにして抜ける
							__log_debug(__FILE__, __LINE__, __METHOD__, $campaign[0]["M94_CAMPAIGN_CD"] . "のキャンペーンコードの" . $arrCampaignInfo[$j] . "の宝はありません");
							$campaign = null;
							break;
						}
						$arrTakara[$arrCampaignInfo[$j]] = $takara[0];
					}
				}
				if (!is_null($campaign))
				{
					$this->m_arrCampaignAgechau[$campaign[0]["M94_CAMPAIGN_CD"]] = $campaign[0];
					$this->m_arrCampaignAgechauTakara[$campaign[0]["M94_CAMPAIGN_CD"]] = $arrTakara;
				}
			}
		}
	}

	/**
	 * キャンペーン反響数テーブル更新
	 *
	 * @param connection $db DBコネクション
	 * @param int $intCampaignKbn キャンペーン区分
	 * @param int $intCampaignCd キャンペーンコード
	 * @param int $intToiawaseKbn 問い合わせ区分
	 * @param array $arrBukken 物件データ（部屋付きキャンペーンのみ）
	 */
	private function UpdLettersCampaign($db, $intCampaignKbn, $intCampaignCd, $intToiawaseKbn, $arrBukken = array())
	{
		$arrLetterCampaign;

		$ymd = date("Ymd");
		$device = $this->m_isMobile;

		// モデル生成
		//$this->_model_bukken = new Inquiry_Model_Apibukken();

		$db_2 = $this->_model_bukken->getDbConnection();
		$this->_model_bukken->startTransaction($db_2);

		try
		{
			$arrLetterCampaign = $this->_model_bukken->GetLettersCampaign($db_2, $intCampaignKbn, $ymd, $intCampaignCd, $device, $intToiawaseKbn, 1);

			if (count($arrLetterCampaign) == 0)
			{
				$this->m_insupdW75LettersCampaignCnt += $this->_model_bukken->InsLettersCampaign($db_2, $intCampaignKbn, $ymd, $intCampaignCd, $device, $intToiawaseKbn, 1);
			}
			else
			{
				$this->m_insupdW75LettersCampaignCnt += $this->_model_bukken->UpdLettersCampaign($db_2, $intCampaignKbn, $ymd, $intCampaignCd, $device, $intToiawaseKbn, 1);
			}

			// キャンペーン応募状況を登録
			$this->m_insW76ApplyCampaignCnt += $this->_model_bukken->InsApplyCampaign($db_2, $intCampaignCd, $intToiawaseKbn, $this->m_strToiawaseId, $intCampaignKbn, $device, $arrBukken);

			$this->_model_bukken->commitTransaction($db_2);
			__log_debug(__FILE__, __LINE__, __METHOD__, "コミットしました");
			$db_2->closeConnection();
		}
		catch (Exception $e)
		{
			$this->_model_bukken->rollbackTransaction($db_2);
			__log_debug(__FILE__, __LINE__, __METHOD__, "ロールバックしました");
			$db_2->closeConnection();
			throw $e;
		}
	}

	/**
	 * あるあるキャンペーン条件文字列化
	 * @param array
	 */
	private function setCampaignData($arrCampaign) {

		$strCampaignJoken = "";

		if (!empty($arrCampaign)) {

			// あるあるキャンペーン取得
			$arrCampaignAruaru = $this->_model_bukken->GetCampaign("1,4", null, $this->m_isMobile);
			foreach ($arrCampaignAruaru as $m_campaign)
			{
				// 選択されているか確認
				if (in_array($m_campaign['M94_CAMPAIGN_CD'], $arrCampaign)) {
					$strCampaignJoken .= "[" . $m_campaign['M94_CAMPAIGN_NAME'] . "]";
				}
			}
		}

		return $strCampaignJoken;
	}

	/**
	 * かんたんリクエストのDB登録・メール送信
	 * @param array
	 */
	public function requestSearch_CompleteProcess(){

		// パラメータ編集用
		$add_params = array();

		//キャンペーンLP経由時にcookieへ格納
		$this->_params["LpCampaignCd"] = $_COOKIE['lp_campaign_cd'];
		//キャンペーンLP経由時にcookieへ格納
		$this->_params["LpRootCd"] = $_COOKIE['lp_root_cd'];

		// モバイル区分・ジャンルコード
		$strGenruFlg = "";
		$this->m_carrier = "";

		if (isset($this->_params['isMobile']) && !empty($this->_params['isMobile'])) {
			$this->m_isMobile = $this->_params['isMobile'];
			$strGenruFlg      = $this->_params['vintGenruFlg'];
			if (empty($strGenruFlg)) {
				$strGenruFlg = "1";
			}
			// iPhone、スマホ、Android用設定
			else if ($strGenruFlg == '91' || $strGenruFlg == '92') {
				$this->m_isMobile = '2';
				$this->m_carrier = "iPhone";
			}
			else if ($strGenruFlg == '93' || $strGenruFlg == '94') {
				$this->m_isMobile = '4';
				$this->m_carrier = "Android";
			}
			else if ($strGenruFlg == '95' || $strGenruFlg == '96') {
				$this->m_isMobile = '3';
				$this->m_carrier = "スマートフォン";
			}
		} else {
			$this->m_isMobile = "0";
			$strGenruFlg      = "0";
		}

		//--- メール判定 ---
		//$this->setSendMailFlag($this->_params['Mail']);
		// ﾛｸﾞ情報格納処理 *****************************************
		$resApi = array();

		try {

			// モデルの呼び出し
			$this->_model = new Inquiry_Model_Apiinquiry();
			$this->_model_bukken = new Inquiry_Model_Apibukken();

			//トランザクション開始
			$db = $this->_model->getDbConnection();
			//トランザクション開始
			$this->_model->startTransaction($db);

			//問合わせID生成
			//問合わせID生成
			$this->m_strToiawaseId = strval($this->GetTimeString()) . strval($this->GetToiawaseSEQ($db));

			$add_params['InqNo'] = $this->m_strToiawaseId;
			$add_params['ComGenruFlg'] = $strGenruFlg;
			$add_params['Seqcount'] = 0;

			//問合せﾕｰｻﾞ情報格納ｸｴﾘ取得処理
			array_push($resApi,$this->_model->insInqUserLog3($db,$this->_params,$add_params));

			//地7域が市区町村の場合
			if($this->_params['area'] == "0"){
				//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
				$this->_params['SrhType'] = 1;

				$add_params['Seqcount'] += 1;
				$add_params['targetPrefCd'] = $this->_params['PrefCd'];
				$add_params['targetCityCd'] = mb_substr($this->_params['CityCd'],2,3);

				$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
			} else { //	沿線・駅の場合
				$this->_params['SrhType'] = 2;

				//駅コード
				$StCdArr = array($this->_params['StCd1'], $this->_params['StCd2'], $this->_params['StCd3']);

				foreach($StCdArr as $stCd){
					if(!empty($stCd)) {
						//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
						$add_params['Seqcount'] += 1;
						$add_params['targetPrefCd'] = $this->_params['PrefCd'];
						$add_params['targetRailCd'] = $this->_params['RailCd'];
						$add_params['targetStCd'] = $stCd;

						$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
					}
				}
			}

			//リクエスト検索情報ログ
			//データセット
			$add_params['ReqData'] = array();
			$add_params['ReqData'] = $this->setRequestData();
			$add_params['ReqData']['iYachinMin'] = 1;
			$tihryo2 = $this->_params['tinryo'];
			$iYachinMax = 30;
			if ($tihryo2 == "999") {
				$iYachinMax = 27;
			} else {
				$tihryo2 = $tihryo2 * 10000;
				$i = 0;
				//==賃料（上限）
				foreach (Apm_Config_Search::$KENSAKU_CHINRYO_MAX as $key => $val){
					if ($tihryo2 == $key) {
						$iYachinMax = $i+1;
						break;
					}
					$i++;
				}
			}
			$add_params['ReqData']['iYachinMax'] = $iYachinMax;
			$add_params['ReqData']['iEkitoho'] = 0;
			if (!empty($this->_params['ekitoho'])) {
				$add_params['ReqData']['iEkitoho'] = $this->_params['ekitoho'];
			}
			$add_params['ReqData']['iSenyuMin'] = 1;
			if (!empty($this->_params['menseki'])) {
				$add_params['ReqData']['iSenyuMin'] = $this->_params['menseki'];
			}
			$add_params['ReqData']['iSenyuMax'] = 14;
			//$add_params['ReqData']['sMadori'] = $this->_params['madori'] > 0 ? '1' : '0';
			$madoriVal = $this->_params['madori'];
			$madoriSaveVal = '';
			for($idx = 1; $idx <= 14; $idx ++ ){
				if($idx == $madoriVal)
					$madoriSaveVal .= '1';
				else
					$madoriSaveVal .= '0';
			}
			$add_params['ReqData']['sMadori'] = $madoriSaveVal;
			$add_params['ReqData']['iKanrihiFlg'] = null;

			array_push($resApi,$this->_model->requestKensakuLog($db,$this->_params,$add_params));

			//選択された店舗
			$SelShopCd = array();

			foreach ($this->_params as $key=>$value)
			{
				if(strncmp($key, "shopdetail_", 11) == 0){
					$shopcd = split("_",$key)[1];
					$SelShopCd[] = $shopcd;
				}
			}

			$add_params['ViewKbn'] = "4";

			//選択されたエリアに店舗が存在しない場合
			if(count($SelShopCd) == 0){
				//リクエスト手動メール情報登録
				$this->_params['Name'] = $this->_params['NameSei'] . "　" . $this->_params['NameMei'];
				array_push($resApi,$this->_model->InsRequestShudouLog($db,$this->_params,$add_params));

				$this->_model->InsInqTenpoLog($add_params['InqNo'], "", $db);

				$this->_params['ShopCd'] = " ";
				array_push($resApi,$this->_model->pageViewLog($db,$this->_params,$add_params));
				$this->shoplist = array();

			} else {
				foreach ($SelShopCd as $shopId){
					$this->_model->InsInqTenpoLog($add_params['InqNo'], $shopId, $db);
					$this->_params['ShopCd'] = $shopId;
					array_push($resApi,$this->_model->pageViewLog($db,$this->_params,$add_params));
				}

				$this->_params['arrSelShop'] = $SelShopCd;
				$this->shoplist = $this->_model->getInqShop2Qry($this->_params);
			}

			// ﾒｰﾙ送信処理 ********************************************
			//--- メール判定 ---
			$this->setSendMailFlag($this->_params['Mail']);

			$add_params['tenpoMailShopCount'] = count($this->shoplist);

			foreach($this->shoplist as $key => $value){
				if($firstflg){
					$add_params['TenpoAll2'] = $value['M05_TENPO_NAME'];
					$firstflg = false;
				}else{
					$add_params['TenpoAll2'] = $add_params['TenpoAll2'] . "\r\n" . $value['M05_TENPO_NAME'];
				}
			}

			//tho 20150117 Start
			// キャンペーン設定
			$CampaignAgechau = array();

			foreach($this->_params as $key => $val) {
				if (strpos($key, 'campaign') !== false) {
					$CampaignAgechau[] = $val;
				}
			}

			$this->_params['CampaignAgechau'] = join ( ';', $CampaignAgechau );

			//error_log($this->_params['CampaignAgechau']);

			//--- あげちゃいますキャンペーン初期化 ---
			$this->MakeCampaignAgechau($this->_params["CampaignAgechau"]);

			//=====キャンペーン反響テーブルカウント(あげちゃいます)=====
			foreach ($this->m_arrCampaignAgechau as $key => $value)
			{
				$this->UpdLettersCampaign($db, $value["M94_CAMPAIGN_KBN"], $value["M94_CAMPAIGN_CD"], 2);
			}

			//あげちゃいますキャンペーンはDBからデータ取得
			//お宝の表示は行わない
			$add_params['strDownloadUrl'] = "";
			$add_params['campaign'] = "";
			foreach ($this->m_arrCampaignAgechauAll as $campaignAll)
			{
				if(array_key_exists($campaignAll["M94_CAMPAIGN_CD"], $this->m_arrCampaignAgechau))
				{
					if($campaignAll["M94_CAMPAIGN_CD"] <> "17"){
						$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　応募する\n";
					}
					else{
						$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　希望する\n";
					}
					$add_params['campaign_str'] .= "　　　◆◆◆" . $campaignAll["M94_CAMPAIGN_NAME"] . "◆◆◆に、応募\n";
				}
				//else
				//{
				//	if($campaignAll["M94_CAMPAIGN_CD"] <> "17"){
				//		$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　応募しない\n";
				//	}
				//	else{
				//		$add_params['campaign'] .= "＜" . $campaignAll["M94_CAMPAIGN_NAME"] . "＞　希望しない\n";
				//	}
				//}

				// アパマン48キャンペーン期間か
				if($campaignAll["M94_CAMPAIGN_CD"] == Apm_Config_Inquiry::AKB_CAMPAIGN_CD)
				{
					//=====キャンペーンダウンロード管理登録
					$this->m_insW25CampaignDownloadMngCnt += $this->_model_bukken->InsCampaignDownload($db, $this->m_strToiawaseId, $campaignAll["ACCESS_KEY"]);

					$add_params['isMobile'] = $this->m_isMobile;
					$add_params['strApaman48DownloadUrl'] = $this->_config['apm']['baseurl']. "AKB48/cp/download?id=". $this->m_strToiawaseId. "&key=".$campaignAll["ACCESS_KEY"];
				}
				//=====キャンペーンダウンロード管理
				if($campaignAll["M94_CAMPAIGN_CD"] == Apm_Config_Inquiry::EXILE_CAMPAIGN_CD)
				{
					// DB登録
					$this->m_insW25CampaignDownloadMngCnt += $this->_model_bukken->InsExileCampaignDownload($db, $this->m_strToiawaseId, $this->m_isMobile, $campaignAll["ACCESS_KEY"]);
					// URI生成
					if ($this->m_isMobile == "0") {
						// PC
						$strExileDownloadUrl = $this->_config['apm']['baseurl']. "exile/cp/download?id=". $this->m_strToiawaseId. "&key=".$campaignAll["ACCESS_KEY"];
					}
					else if ($this->m_isMobile == "1") {
						// mobile
						$strExileDownloadUrl = $this->_config['apm']['baseurl']. "mobile/exile/download?id=". $this->m_strToiawaseId. "&key=".$campaignAll["ACCESS_KEY"];
					}
					else {
						// SP
						$strExileDownloadUrl = $this->_config['apm']['baseurl']. "exile/cp/download/sp?id=". $this->m_strToiawaseId. "&kbn=".$this->m_isMobile. "&key=".$campaignAll["ACCESS_KEY"];
					}
					// メールMSG生成
					$strDownloadMsg = "";
					if ($this->m_isMobile == "0") {
						// PC
						$strDownloadMsg .= "■スクリーンセーバーダウンロード\n";
						$strDownloadMsg .= "現在、APAMANxEXILEキャンペーン中につき、お問合わせいただいた方全員に\n";
						$strDownloadMsg .= "もれなくAPAMANxEXILEオリジナルスクリーンセーバーを差し上げています。\n";
						$strDownloadMsg .= "下記、URLからダウンロードしてお楽しみください。\n";
						$strDownloadMsg .= "※ダウンロードは3回までとなっておりますのでご注意ください。\n";
					}
					else {
						$strDownloadMsg .= "■壁紙ダウンロード\n";
						$strDownloadMsg .= "現在、APAMANxEXILEキャンペーン中につき、お問合わせいただいた方全員に\n";
						$strDownloadMsg .= "もれなくAPAMANxEXILEオリジナル壁紙を差し上げています。\n";
						$strDownloadMsg .= "下記、URLからダウンロードしてお楽しみください。\n";
					}
					$strDownloadMsg .= " \n";
					$strDownloadMsg .= $strExileDownloadUrl."\n";

					$add_params['strDownloadUrl'] .= $strDownloadMsg;
				}
			}
			//tho 20150117 End

			$add_params['is_kantanrequest'] = "1";
			$add_params['DspKibouToshi'] = $this->_params['area'] == "0" ? $this->_params['hidAreaDisplay'] : "";
			$add_params['DspKibouEnsen'] = $this->_params['area'] == "1" ? $this->_params['hidAreaDisplay'] : "";

			$this->_params['TimeStr'] = date("Y/m/d H:i:s");

			$result =  $this->SendMailMain($this->_params["Mail"],$add_params);

			if($result == "0"){
				$this->raiseError('メール送信エラー');
			}

			__log_debug(__FILE__, __LINE__, __METHOD__, "コミットします");
			$this->_model->commitTransaction($db);
			$db->closeConnection();

			$result = 1;

		} catch (Exception $e) {

			error_log( $e->getMessage());

			__log_debug(__FILE__, __LINE__, __METHOD__, "ロールバックします");
			$this->_model->rollbackTransaction($db);
			$db->closeConnection();
			$result = 0;
		}

		// 返却データ作成
		$resResult = array('api_result' => array('result' => $result,'res_detail' => $resApi));
		//$resResult['CV_ToiawaseId'] = $this->m_strToiawaseId;
		// 返却処理
		//$this->_api_data = $resResult;
		//$this->display();
	}

}
?>
